package com.jobsika.client;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gwt.http.client.URL;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Window;

public class Util {
	public static DateTimeFormat dtf = DateTimeFormat.getFormat("dd MMMM, yyyy h:mmaa");
	public static String searchtext = "Need a job? Starts here.";
	
	public static String USER = "u";
	public static String POST = "p";
	public static String HOME = "h";
	public static String ADD = "a";
	public static String ACTION = "act";
	public static String LOGIN = "login";
	public static String LOGOUT = "logout";
	public static String REGISTER = "reg";
	public static String QUERY = "q";
	public static String BROWSE = "b";
	public static String PAGE = "pg";
	
	public static String getBaseURL() {
		return Window.Location.getProtocol() + "//" + Window.Location.getHost()
				+ "/";
	}

	static Map<String, List<String>> buildListParamMap(String queryString) {
		Map<String, List<String>> out = new HashMap<String, List<String>>();

		if (queryString != null && queryString.length() > 0) {

			for (String kvPair : queryString.split("&")) {
				String[] kv = kvPair.split("=", 2);
				if (kv[0].length() == 0) {
					continue;
				}

				List<String> values = out.get(kv[0]);
				if (values == null) {
					values = new ArrayList<String>();
					out.put(kv[0], values);
				}
				values.add(kv.length > 1 ? URL.decodeComponent(kv[1]) : "");
			}
		}

		for (Map.Entry<String, List<String>> entry : out.entrySet()) {
			entry.setValue(Collections.unmodifiableList(entry.getValue()));
		}

		out = Collections.unmodifiableMap(out);

		return out;
	}
}
